package controller;

import java.util.Properties;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

public class DefaultConfig extends JFinalConfig {
    
    private static Properties properties;
    
    public static String getPropery(String key) {
        return properties.getProperty(key).trim();
    }
    
    public static Integer getIntPropery(String key) {
        return Integer.valueOf(getPropery(key));
    }
    
    public static Long getLongPropery(String key) {
        return Long.valueOf(getPropery(key));
    }
    
    public static Boolean getBoolPropery(String key) {
        return Boolean.valueOf(getPropery(key));
    }
    
    @Override
    public void configConstant(Constants me) {
        me.setDevMode(true);
        me.setViewType(ViewType.JSP);
        /*me.setError404View("/WEB-INF/view/doc/nofind404.jsp");
        me.setError500View("/WEB-INF/view/doc/nofind500.jsp");*/
        properties = loadPropertyFile("config.properties");
    }

    @Override
    public void configHandler(Handlers arg0) {
        // TODO 自动生成的方法存根
        arg0.add(new ContextPathHandler("ctx_path"));

    }

    @Override
    public void configInterceptor(Interceptors arg0) {
        // TODO 自动生成的方法存根

    }

    @Override
    public void configPlugin(Plugins me) {
        C3p0Plugin cp = new C3p0Plugin(getProperty("jdbc_url"), getProperty("jdbc_user"), getProperty("jdbc_password"));
        me.add(cp);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
        me.add(arp);
        
    }

    @Override
    public void configRoute(Routes me) {
    	me.add("/", MainController.class);
    	me.add("/member", MemberController.class);
    	me.add("/buy",BuyController.class);
    }
}
